package ExerciseThree;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import org.junit.Test;

public class BufferedInputStreamTest {
	@Test
	public void test1()
	{
		BufferedInputStream bis=null;
		BufferedOutputStream bos=null;
		try {
			File file1 = new File("微信图片_20220625223251.jpg");
			File file2 = new File("D:\\JavaProject\\Exercise2\\src\\微信图片_202206252232510824.jpg");
			FileInputStream fis = new FileInputStream(file1);
			FileOutputStream fos = new FileOutputStream(file2);
			bis = new BufferedInputStream(fis);
			bos = new BufferedOutputStream(fos);
			byte buffer[] = new byte[20];
			int len;
			while((len = bis.read(buffer))!=-1)
			{
				bos.write(buffer,0,len);
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}finally
		{
			if(bos!=null)
			{
				try {
					bos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			if(bis!=null)
			{
				try {
					bis.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

}
